package vista;

import controlador.ControladorIngrediente;

import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaIngredientes extends javax.swing.JFrame {

    private ControladorIngrediente control;
    /** Creates new form VistaIngrediente */
    public VentanaIngredientes() {
        initComponents();
        control= new ControladorIngrediente(this);
        limpiar();
        addAction();
    }

    public void addListener(ActionListener escuchador){
        btnSalir.addActionListener(escuchador);
        btnActualizar.addActionListener(escuchador);
        btnCancelar.addActionListener(escuchador);
        btnBuscar.addActionListener(escuchador);
        btnRegistrar.addActionListener(escuchador);
    }

     public void addAction(){
        btnSalir.setActionCommand("Salir");
        btnRegistrar.setActionCommand("Registrar");
        btnCancelar.setActionCommand("Cancelar");
        btnActualizar.setActionCommand("Actualizar");
        btnBuscar.setActionCommand("Buscar");
    }

    public boolean hayVacios(){
        for (int i = 0; i < getTextos().size(); i++) {
            JTextField texto = getTextos().get(i);
                JOptionPane.showMessageDialog(new JFrame(),"Campos vacios","Cari Burguer",JOptionPane.INFORMATION_MESSAGE);
                return true;
            }
       
        return false;
    }

    public boolean validoNumeros(){
        try{
            if(Double.parseDouble(txtCodigo.getText())<=0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El codigo es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
            if(Double.parseDouble(txtStock.getText())<0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"El stock es invalido","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
             if(Double.parseDouble(txtComprada.getText())<0){
                txtCodigo.setText("");
                JOptionPane.showMessageDialog(new JFrame(),"La cantidad es invalida","Cari Burguer",JOptionPane.WARNING_MESSAGE);
                return false;
           }
       }catch(NumberFormatException ex){
           JOptionPane.showMessageDialog(new JFrame(),"Ingreso letras en lugar de numeros","Cari Burguer",JOptionPane.WARNING_MESSAGE);
           return false;
       }
    return true;
    }

    public boolean validarCodigoVacio(){
        if(txtCodigo.getText().equals("")){
                JOptionPane.showMessageDialog(new JFrame(),"Codigo vacio","Calle el Hambre Arena Aplaza",JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

        return true;
    }

    public void mostrar(){
        txtCodigo.setEditable(false);
        txtStock.setEditable(false);
        txtDescripcion.setEditable(false);
        txtComprada.setVisible(true);
        jLabel7.setVisible(true);
        txtComprada.setText("0");
    }

    
     public void limpiar(){
        txtCodigo.setText("");
        txtDescripcion.setText("");
        txtStock.setText("");
        txtStock.setEditable(true);
        txtCodigo.setEditable(true);
        txtDescripcion.setEditable(true);
        txtComprada.setVisible(false);
        jLabel7.setVisible(false);
        txtComprada.setText("0");
    }

    public LinkedList<JTextField> getTextos() {
        LinkedList<JTextField> v = new LinkedList<JTextField>();
        return v;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public JTextField getTxtComprada() {
        return txtComprada;
    }

    public JTextField getTxtDescripcion() {
        return txtDescripcion;
    }

    public JTextField getTxtStock() {
        return txtStock;
    }    

   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(null);

        jPanel1.add(txtStock);

        txtComprada.setText("0");
        jPanel1.add(txtComprada);

        jLabel6.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        jLabel6.setText("Codigo");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(26, 38, 72, 23);
        jLabel6.setBackground(new java.awt.Color(255,255,255));

        jLabel5.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        jLabel5.setText("Stock");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(27, 138, 62, 21);

        jLabel1.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        jLabel1.setText("Descripcion");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(26, 70, 99, 25);
        {
        	txtCodigo = new javax.swing.JTextField();
        	jPanel1.add(txtCodigo);
        	txtCodigo.setBounds(127, 38, 198, 22);
        	txtCodigo.setBackground(new java.awt.Color(255,255,255));
        }
        {
        	txtComprada = new javax.swing.JTextField();
        	jPanel1.add(txtComprada);
        	txtComprada.setFont(new java.awt.Font("Arial", 0, 13));
        	txtComprada.setBounds(127, 105, 198, 24);
        	txtComprada.setSize(198, 20);
        }
        {
        	txtDescripcion = new javax.swing.JTextField();
        	jPanel1.add(txtDescripcion);
        	txtDescripcion.setFont(new java.awt.Font("Arial", 0, 13));
        	txtDescripcion.setBounds(127, 72, 198, 20);
        	txtDescripcion.setBackground(new java.awt.Color(255,255,255));
        }
        {
        	txtStock = new javax.swing.JTextField();
        	jPanel1.add(txtStock);
        	txtStock.setFont(new java.awt.Font("Arial", 0, 13));
        	txtStock.setBounds(127, 139, 198, 24);
        	txtStock.setBackground(new java.awt.Color(255,255,255));
        	txtStock.setSize(198, 20);
        }
        
        jPanel1.add(txtDescripcion);

        jLabel7.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        jLabel7.setText("Cantidad");
        jPanel1.add(jLabel7);
        jLabel7.setBounds(26, 103, 87, 22);
        {
        	btnCancelar = new javax.swing.JButton();
        	jPanel1.add(btnCancelar);
        	btnCancelar.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        	btnCancelar.setText("Cancelar");
        	btnCancelar.setBounds(43, 217, 100, 23);
        }
        {
        	jLabel2 = new javax.swing.JLabel();
        	jPanel1.add(jLabel2);
        	jLabel2.setFont(new java.awt.Font("Ubuntu",1,15)); // NOI18N
        	jLabel2.setText("Ingrediente");
        	jLabel2.setBounds(129, 6, 104, 22);
        }
        {
        	btnRegistrar = new javax.swing.JButton();
        	jPanel1.add(btnRegistrar);
        	btnRegistrar.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        	btnRegistrar.setText("Registrar");
        	btnRegistrar.setBounds(43, 183, 100, 23);
        }
        {
        	btnBuscar = new javax.swing.JButton();
        	jPanel1.add(btnBuscar);
        	btnBuscar.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        	btnBuscar.setText("Buscar");
        	btnBuscar.setBounds(211, 183, 100, 23);
        }
        {
        	btnActualizar = new javax.swing.JButton();
        	jPanel1.add(btnActualizar);
        	btnActualizar.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        	btnActualizar.setText("Actualizar");
        	btnActualizar.setBounds(211, 217, 100, 23);
        }
        {
        	btnSalir = new javax.swing.JButton();
        	jPanel1.add(btnSalir);
        	btnSalir.setFont(new java.awt.Font("Ubuntu",1,13)); // NOI18N
        	btnSalir.setText("Salir");
        	btnSalir.setBounds(129, 250, 100, 23);
        }
        jPanel1.add(txtCodigo);
        txtCodigo.setSize(198, 20);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 362, 299);
        jPanel1.setBackground(new java.awt.Color(255,255,255));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        this.setBounds(0, 0, 367, 318);
        this.setEnabled(false);
        this.setTitle("Registrar Ingredientes");
    }// </editor-fold>//GEN-END:initComponents


   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaIngredientes().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtComprada;
    private javax.swing.JTextField txtDescripcion;
    private javax.swing.JTextField txtStock;
    // End of variables declaration//GEN-END:variables

}
